﻿using INTEX.DataBase;
using INTEX.DataBase.Tools;
using ReflectionStudio.Components.UserControls;
using ReflectionStudio.Core;
using ReflectionStudio.Core.Events;
using ReflectionStudio.Core.Helpers;
using System;
using System.Linq;
using System.Data.Linq;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OracleClient;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Text;
using System.Threading;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for SummaryForm.xaml
    /// </summary>

    public partial class YCAMDPLAN : DocumentBase
    {

        Queue<DataSet> JobQueue;
        bool IsSupplierLoded = false;

        string root = Path.Combine(PathHelper.ApplicationPath, "Report\\Interface\\");
        public OracleConnection OracleDB;
        public IntexReptServBLClient proxy;
        private Dictionary<string, object> dicParamater;
        INTEXDBC INTEXDBC;
        public SETINTEXDB SetData
        {
            get
            {
                return (SETINTEXDB)TryFindResource("SetData");
            }
        }
        public SETINTEXDB SetTmp
        {
            get
            {
                return (SETINTEXDB)TryFindResource("SetTmp");
            }
        }
        BackgroundWorker bgWorker;
        public bool IsPlanMode
        {
            get
            {
                if (ChkPlanMode.IsChecked == true)
                {
                    return true;
                }
                return false;
            }
        }
        public bool IsOverride
        {
            get
            {
                if (ChkOverride.IsChecked == true)
                {
                    return true;
                }
                return false;
            }
        }
        public bool IsShowPlanned
        {
            get
            {
                if (ChkPlanned.IsChecked == true)
                {
                    return true;
                }
                return false;
            }
        }
        public bool IsMatMode
        {
            get
            {
                if (ChkMatMode.IsChecked == true)
                {
                    return true;
                }
                return false;
            }
            set
            {
                if (value)
                {
                    ChkMatMode.IsChecked = true;
                }
                else
                {
                    ChkMatMode.IsChecked = false;
                }
            }
        }
        bool IsRunning = false;
        public SETINTEXDB Set4ITX
        {
            get
            {
                return (SETINTEXDB)TryFindResource("Set4ITX");
            }
        }
        string Today
        {
            get
            {
                return System.DateTime.Now.Year.ToString()
                    + m_Data.Right("00" + System.DateTime.Now.Month.ToString(), 2)
                    + m_Data.Right("00" + System.DateTime.Now.Day.ToString(), 2);
            }
        }
        string JobType = "AUTOEK";
        YCAMDPLANData m_Data;
        SETINTEXDB.ICC_EKPOSDataTable tpEKPOS = new SETINTEXDB.ICC_EKPOSDataTable();
        bool success = true;
        string failreason = "";
        public string pSType
        {
            get
            {
                return m_Data.Left(SType.Text + "  ", 1);
            }
            set
            {
                SType.Text = value;
            }
        }
        public string pSKRS
        {
            get
            {
                return m_Data.Left(SKRS.Text + "   ", 2);
            }
            set
            {
                SKRS.Text = value;
            }
        }
        public string pSLFD
        {
            get
            {
                return m_Data.Left(SLFD.Text + "       ", 6);
            }
            set
            {
                SLFD.Text = value;
            }
        }
        public string pSPOS
        {
            get
            {
                return m_Data.Left(SPOS.Text + "   ", 3);
            }
            set
            {
                SPOS.Text = value;
            }
        }
        public string pSAID
        {
            get
            {
                return m_Data.Left(SAID.Text + "   ", 3);
            }
            set
            {
                SAID.Text = value;
            }
        }
        public double pSQTY
        {
            get
            {
                if (SQTY.Text.ToString() == "")
                    return 0;
                return System.Convert.ToDouble(SQTY.Text);
            }
            set
            {
                SQTY.Text = value.ToString();
            }
        }
        #region=====vwITXXDECK=======
        CollectionViewSource vwITXXDECK
        {
            get
            {
                return (CollectionViewSource)this.TryFindResource("vwITXXDECK");
            }
        }
        DataRow dwITXXDECK
        {
            get
            {
                if (vwITXXDECK.View == null)
                    return null;
                if ((DataRowView)vwITXXDECK.View.CurrentItem == null)
                    return null;
                return ((DataRowView)vwITXXDECK.View.CurrentItem).Row;
            }
        }
        #endregion
        #region=====vwXDECK=======
        CollectionViewSource vwXDECK
        {
            get
            {
                return (CollectionViewSource)this.TryFindResource("vwXDECK");
            }
        }
        DataRow dwXDECK
        {
            get
            {
                if (vwXDECK.View == null)
                    return null;
                if (vwXDECK.View.CurrentItem == null)
                    return null;
                return ((DataRowView)vwXDECK.View.CurrentItem).Row;
            }
        }
        #endregion
        #region=====vwITXABPOS=======
        CollectionViewSource vwITXABPOS
        {
            get
            {
                return (CollectionViewSource)this.TryFindResource("vwITXABPOS");
            }
        }
        DataRow dwITXABPOS
        {
            get
            {
                if (vwITXABPOS.View == null)
                    return null;
                if ((DataRowView)vwITXABPOS.View.CurrentItem == null)
                    return null;
                return ((DataRowView)vwITXABPOS.View.CurrentItem).Row;
            }
        }
        #endregion
        #region=====vwITXEKPOS=======
        CollectionViewSource vwITXEKPOS
        {
            get
            {
                return (CollectionViewSource)this.TryFindResource("vwITXEKPOS");
            }
        }
        DataRow dwITXEKPOS
        {
            get
            {
                if (vwITXEKPOS.View == null)
                    return null;
                if ((DataRowView)vwITXEKPOS.View.CurrentItem == null)
                    return null;
                return ((DataRowView)vwITXEKPOS.View.CurrentItem).Row;
            }
        }
        #endregion
        #region=====vwITXSTOCK=======
        CollectionViewSource vwITXSTOCK
        {
            get
            {
                return (CollectionViewSource)this.TryFindResource("vwITXSTOCK");
            }
        }
        DataRow dwITXSTOCK
        {
            get
            {
                if (vwITXSTOCK.View == null)
                    return null;
                if ((DataRowView)vwITXSTOCK.View.CurrentItem == null)
                    return null;
                return ((DataRowView)vwITXSTOCK.View.CurrentItem).Row;
            }
        }
        #endregion
        #region=====vwITXAB15=======
        CollectionViewSource vwITXAB15
        {
            get
            {
                return (CollectionViewSource)this.TryFindResource("vwITXAB15");
            }
        }
        DataRow dwITXAB15
        {
            get
            {
                if (vwITXAB15.View == null)
                    return null;
                if ((DataRowView)vwITXAB15.View.CurrentItem == null)
                    return null;
                return ((DataRowView)vwITXAB15.View.CurrentItem).Row;
            }
        }
        #endregion

        public YCAMDPLAN()
        {
            InitializeComponent();
            this.Name = "辅料采购";
            JobQueue = new Queue<DataSet>();
        }
        public override void SetUp(Dictionary<string, object> dicParamater)
        {
            try
            {
                using (new LongOperation(this, "读取符合条件的记录"))
                {
                    base.SetUp(dicParamater);
                    this.dicParamater = dicParamater;
                    OracleDB = (OracleConnection)dicParamater["OracleDB"];
                    proxy = (IntexReptServBLClient)dicParamater["proxy"];
                    m_Data = new YCAMDPLANData(OracleDB, proxy);
                    INTEXDBC = new INTEXDBC(OracleDB, proxy);
                    txtUserID.Text = (string)dicParamater["User"];
                    txtPassword.Password = (string)dicParamater["Pwd"];
                    cmbKRS.Text = "MP";
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        #region======common========
        private void Windows_Loaded(object sender, RoutedEventArgs e)
        {
            bgWorker = new BackgroundWorker();
            bgWorker.DoWork += new DoWorkEventHandler(bgWorker_DoWork);
            bgWorker.RunWorkerCompleted += bgWorker_RunWorkerCompleted;
            vwITXABPOS.View.CurrentChanged += vwITXABPOS_CurrentChanged;
            vwXDECK.View.CurrentChanged += vwXDECK_CurrentChanged;
            vwITXEKPOS.View.CurrentChanged += vwITXEKPOS_CurrentChanged;
            vwITXSTOCK.View.CurrentChanged += vwITXSTOCK_CurrentChanged;
            vwITXAB15.View.CurrentChanged += vwITXAB15_CurrentChanged;
        }

        void vwITXAB15_CurrentChanged(object sender, EventArgs e)
        {
            if (dwITXAB15 == null)
                return;
            var query = from row in SetData.ICC_XDECK.AsEnumerable()
                        where row["ART"].ToString().Trim() == dwITXAB15["ABAART"].ToString().Trim()
                        && row["VAR"].ToString().Trim() == dwITXAB15["ABAVAR"].ToString().Trim()
                        && row["COLOR"].ToString().Trim() == dwITXAB15["ABAFARBE"].ToString().Trim()
                        && row["ASIZE"].ToString().Trim() == dwITXAB15["ABAGROE"].ToString().Trim()
                        select row;
            int index = -1;

            foreach (DataRow row in SetData.ICC_XDECK.Rows)
            {
                index++;
                if (row["ART"].ToString().Trim() == dwITXAB15["ABAART"].ToString().Trim()
                      && row["VAR"].ToString().Trim() == dwITXAB15["ABAVAR"].ToString().Trim()
                      && row["COLOR"].ToString().Trim() == dwITXAB15["ABAFARBE"].ToString().Trim()
                      && row["ASIZE"].ToString().Trim() == dwITXAB15["ABAGROE"].ToString().Trim()
                    )
                {
                    vwXDECK.View.MoveCurrentToPosition(index);
                    break;
                }
            }
        }
        void vwITXEKPOS_CurrentChanged(object sender, EventArgs e)
        {
            if (!IsMatMode)
                return;
            if (dwITXEKPOS == null)
                return;
            try
            {
                pSType = "P";
                pSKRS = dwITXEKPOS["EKPAUFKRS"].ToString();
                pSLFD = dwITXEKPOS["EKPAUFLFD"].ToString();
                pSPOS = dwITXEKPOS["EKPAUFPOS"].ToString();
                pSAID = dwITXEKPOS["EKPAID"].ToString();
                pSQTY = System.Convert.ToDouble(dwITXEKPOS["EKPQTYFREE"].ToString());
                vwITXXDECK.View.MoveCurrentTo(-1);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        void vwITXABPOS_CurrentChanged(object sender, EventArgs e)
        {

            DataSet SResult = new DataSet();
            if (dwITXABPOS == null)
                return;
            SResult = m_Data.LoadABPOSData(dwITXABPOS);
            Set4ITX.ICC_ABAUFM.Clear();
            Set4ITX.ICC_ABAUFM.Merge(SResult.Tables[0]);            
        }
        void vwITXSTOCK_CurrentChanged(object sender, EventArgs e)
        {
            if (!IsMatMode)
                return;
            if (dwITXSTOCK == null)
                return;
            pSType = "B";
            pSKRS = dwITXSTOCK["LO"].ToString();
            pSLFD = dwITXSTOCK["LB"].ToString();
            pSPOS = "000";
            pSAID = dwITXSTOCK["BAID"].ToString();
            pSQTY = System.Convert.ToDouble(dwITXSTOCK["QTYFREE"].ToString());
            vwITXXDECK.View.MoveCurrentTo(-1);
        }
        void vwXDECK_CurrentChanged(object sender, EventArgs e)
        {
            if (!IsPlanMode)
                return;
            if (dwXDECK == null)
                return;
            JobType = "LOADXDECK";
            ArrayList args = new ArrayList();
            args.Add(dwXDECK);
            args.Add(IsShowPlanned);
            if (!IsRunning)
            {
                bgWorker.RunWorkerAsync(args);
            }
            else
            {
                //MessageBox.Show("请等待后台进程完成");
            }
        }
        void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            IsRunning = false;
            WaitPanel.Stop();
        }
        void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            if (!IsRunning)
            {
                IsRunning = true;
            }
            this.Dispatcher.Invoke(new Action(() =>
            {
                WaitPanel.AutoPlay = true;
            }));
            AutoRun(e);
        }

        private void btnLogIn_Click(object sender, RoutedEventArgs e)
        {
            {

                EventDispatcher.Instance.RaiseStatus(txtLogIn.Text, StatusEventType.UserLogIn);
            }
        }
        private void btnRefresh_Click(object sender, RoutedEventArgs e)
        {
            JobType = "LOADREQ";
            if (!IsRunning)
            {
                bgWorker.RunWorkerAsync();
            }
            else
            {
                MessageBox.Show("请等待后台进程完成");
            }
        }

        private void ChkMatMode_Checked(object sender, RoutedEventArgs e)
        {
            if (IsMatMode)
            {
                zonePlan.IsExpanded = false;
                //zoneSource.IsExpanded = true;
            }
            else
            {
                zonePlan.IsExpanded = true;
                //zoneSource.IsExpanded = true;
            }
        }


        private void btnRefreshPurchase_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!IsSupplierLoded)
                {
                    SetData.Merge(m_Data.LoadSupplier());
                    IsSupplierLoded = true;
                }
                if (dlgTempEK.IsEnabled)
                {
                    dlgTempEK.IsEnabled = false;
                    dlgTempEK.Visibility = Visibility.Hidden;
                }
                if (!imgneworder.IsEnabled)
                {
                    imgneworder.IsEnabled = true;
                    imgneworder.Visibility = Visibility.Visible;
                }
                JobType = "AUTOEK";
                if (!IsRunning)
                {
                    bgWorker.RunWorkerAsync();
                }
                else
                {
                    MessageBox.Show("请等待后台程序完成");
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        private void btnITXPurchase_Click(object sender, RoutedEventArgs e)
        {
            bool IsSuccess = true;
            string msg = "";
            m_Data.CheckData(Set4ITX, ref IsSuccess, ref msg);
            if (!IsSuccess)
            {
                MessageBox.Show(msg);
                return;
            }
            if (imgneworder.IsEnabled)
            {
                imgneworder.IsEnabled = false;
                imgneworder.Visibility = Visibility.Hidden;
            }
            JobType = "PUSH2ITX";
            if (!IsRunning)
            {
                bgWorker.RunWorkerAsync();
            }
            else
            {
                MessageBox.Show("请等待后台程序完成");
            }

        }
        public void ITXPurchase()
        {
            string xml = @"C:\IntexReport\Data\YCAATEK\01Temp\EK" + DateTime.Now.ToFileTime().ToString() + ".XML";
            SetTmp.Clear();
            DataTable tbtemp = Set4ITX.ICC_EKPOS.Copy();
            tbtemp.TableName = "EKPOS_EXT";
            foreach (DataRow rw in tbtemp.Rows)
            {
                rw["EKPME1"] = System.Math.Round(System.Convert.ToDecimal(rw["EKPME1"].ToString()) * 100, 0);
                rw["EKPWE1"] = System.Math.Round(System.Convert.ToDouble(rw["EKPME1"].ToString())
                    * System.Convert.ToDouble(rw["EKPPRME"].ToString())
                    * 0.001, 0);
            }
            SetTmp.Merge(tbtemp);
            this.SetTmp.WriteXml(xml);
            m_Data.Send2Intex(dicParamater);
            this.Dispatcher.Invoke(new Action(() =>
                     {
                         Set4ITX.ICC_EKPOS.Clear();
                         btnITXPurchase.IsEnabled = false;
                     }));
        }

        private void dlgITXDECK_MouseRightButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (dwITXXDECK == null)
                return;
            dwITXXDECK["ABAAUFTYP"] = "N";
            dwITXXDECK["ABAAUFKRS"] = "  ";
            dwITXXDECK["ABAAUFLFD"] = "      ";
            dwITXXDECK["ABAAUFPOS"] = "   ";
            dwITXXDECK["ABAQTYALLOCATE"] = 0;
            dwITXXDECK["ABAQTYRESERVE"] = 0;
            INTEXDBC.UpdateICC_ABAUFM(dwITXXDECK, 1);//这里是满足需求的关系，若是部分满足，则拆分数量 
        }

        private void btnRefreshAllocation_Click(object sender, RoutedEventArgs e)
        {
            INTEXDBC.UpdateICC_ABAUFM(dwITXXDECK, 1);//这里是满足需求的关系，若是部分满足，则拆分数量
        }
        private void btnPurchase_Click(object sender, RoutedEventArgs e)
        {
            DataTable temp = new DataTable();
            try
            {
                if (IsRunning)
                    return;
                if (cmbKRS.Text.ToString().Trim() == "")
                {
                    MessageBox.Show("请确定前缀");
                    return;
                }
                if (!dlgTempEK.IsEnabled)
                {
                    dlgTempEK.IsEnabled = true;
                    dlgTempEK.Visibility = Visibility.Visible;
                    IsMatMode = false;
                }
                temp = SetData.ICC_XDECK.Clone();
                foreach (DataRowView vw in dlgXDECK.SelectedItems)
                {
                    string ART = vw.Row["ART"].ToString();
                    string VAR = vw.Row["VAR"].ToString();
                    string FARBE = vw.Row["COLOR"].ToString();
                    string SIZE = vw.Row["ASIZE"].ToString();

                    var emp = from DataRow rw in SetData.ICC_XDECK.AsEnumerable()
                              where rw["ART"].ToString() == ART
                              && rw["VAR"].ToString() == VAR
                              && rw["COLOR"].ToString() == FARBE
                              && rw["ASIZE"].ToString() == SIZE
                              select rw;
                    temp.Merge(emp.CopyToDataTable());
                }

                foreach (DataRow vw in temp.Rows)
                {
                    string ART = vw["ART"].ToString();
                    string VAR = vw["VAR"].ToString();
                    string FARBE = vw["COLOR"].ToString();
                    string SIZE = vw["ASIZE"].ToString();
                    DataRow rek = tpEKPOS.NewICC_EKPOSRow();
                    //byte[] bytes = Encoding.ASCII.GetBytes(m_Data.Left(vw["MDMAT"].ToString() + "                        ", 20));
                    rek["EKPART"] = m_Data.Left(vw["ART"].ToString() + "                        ", 20);
                    //bytes = Encoding.ASCII.GetBytes(m_Data.Left(vw["MDVAR"].ToString() + "     ", 3));
                    rek["EKPVAR"] = m_Data.Left(vw["VAR"].ToString() + "     ", 3);
                    //bytes = Encoding.ASCII.GetBytes(m_Data.Left("               ", 10));
                    rek["EKPFARBE"] = m_Data.Left(vw["COLOR"].ToString() + "     ", 10);
                    rek["EKPDESS"] = m_Data.Left("               ", 10);
                    rek["EKPCOL"] = m_Data.Left("               ", 10);
                    rek["EKPBESCH"] = m_Data.Left("               ", 10);
                    rek["EKPZUSTAND"] = m_Data.Left("               ", 4);
                    rek["EKPGROE"] = m_Data.Left(vw["ASIZE"].ToString() + "     ", 7);
                    rek["EKPNEUD"] = Today;
                    rek["EKPNEUB"] = m_Data.Left(txtUserID.Text.ToString() + "      ", 8);
                    rek["EKPAUFKRS"] = m_Data.Left(cmbKRS.Text.ToString().Trim() + "   ", 2);
                    rek["EKPME1"] = vw["REQ"].ToString();// System.Math.Round(System.Convert.ToDecimal(vw["MDMENGE"].ToString()) * 100, 0);
                    rek["EKPMEEH"] = vw["UM"];
                    rek["EKPMEEHFKT"] = "000001000000";
                    rek["EKPLSGRPBEZ"] = m_Data.Left("                                                                                                 ", 20);
                    rek["EKPSMENGE"] = "0";
                    tpEKPOS.Rows.Add(rek);
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            finally
            {
                DataRow[] rows;
                foreach (DataRow vw in temp.Rows)
                {
                    string ART = vw["ART"].ToString();
                    string VAR = vw["VAR"].ToString();
                    string FARBE = vw["COLOR"].ToString();
                    string SIZE = vw["ASIZE"].ToString();
                    rows = SetData.ICC_XDECK.Select("ART = '" + ART + "' AND VAR='" + VAR + "' AND COLOR='" + FARBE + "' AND ASIZE='" + SIZE + "'");
                    foreach (DataRow rw in rows)
                    {
                        rw.Delete();
                    }
                }
                SetData.AcceptChanges();
                SetTmp.ICC_EKPOS.Clear();
                SetTmp.Merge(tpEKPOS);
            }
        }
        private void dlgITXDECK_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            try
            {
                DataRow row = dwITXXDECK;
                string krs = row["ABAVKAUFKRS"].ToString();
                string lfd = row["ABAVKAUFLFD"].ToString();
                string pos = row["ABAVKAUFPOS"].ToString();
                string ABAID = row["ABAID"].ToString();

                var query = from rx in SetData.ABPOS.AsEnumerable()
                            where rx["ABPAUFKRS"].ToString() == krs
                            && rx["ABPAUFLFD"].ToString() == lfd
                            && rx["ABPAUFPOS"].ToString() == pos
                            select rx;
                Set4ITX.ABPOS.Clear();
                Set4ITX.ABPOS.Merge(query.CopyToDataTable());
                if (vwITXABPOS.View != null)
                {
                    vwITXABPOS.View.MoveCurrentToFirst();
                }

                if (IsMatMode)
                {
                    if (pSType.Trim() == "")
                        return;
                    if (pSQTY <= 0)
                        return;
                    var query1 = from rx in SetData.ICC_ABAUFM.AsEnumerable()
                                 where rx["ABAID"].ToString() == ABAID
                                 select rx;
                    foreach (DataRow rx in query1)
                    {
                        ///2.	若可用数量>需求数量，则用留位数量满足需求，不关闭需求
                        ///3.	若可用数量<需求数量，在不允许执行
                        ///
                        double rqty = System.Convert.ToDouble(rx["ABARESMG"].ToString());
                        string atyp = rx["ABAAUFTYP"].ToString().Trim();
                        string akrs = rx["ABAAUFKRS"].ToString().Trim();
                        string alfd = rx["ABAAUFLFD"].ToString().Trim();
                        string apos = rx["ABAAUFPOS"].ToString().Trim();
                        if (rx["ABAAUFTYP"].ToString().Trim() != "N")
                        {
                            if (!IsOverride)
                            {
                                return;
                            }
                            //如果不在可以覆盖模式下，如果已经有了分配，则不再覆盖
                        }
                        if (atyp.Trim() == pSType.Trim()
                            && akrs.Trim() == pSKRS.Trim()
                            && alfd.Trim() == pSLFD.Trim()
                            && apos.Trim() == pSPOS.Trim()
                            )
                        {
                            return;
                        }

                        if (pSQTY >= rqty)
                        {
                            #region====数量足够=====
                            rx["ABAAUFTYP"] = pSType;
                            rx["ABAAUFKRS"] = pSKRS;
                            rx["ABAAUFLFD"] = pSLFD;
                            rx["ABAAUFPOS"] = pSPOS;
                            pSQTY -= rqty;
                            switch (pSType)
                            {
                                case "B":
                                    rx["ABAQTYALLOCATE"] = rqty;
                                    rx["ABAQTYRESERVE"] = 0;
                                    dwITXSTOCK["QTYFREE"] = pSQTY;
                                    break;
                                case "P":
                                    rx["ABAQTYALLOCATE"] = 0;
                                    rx["ABAQTYRESERVE"] = rqty;
                                    dwITXEKPOS["EKPQTYFREE"] = pSQTY;
                                    break;
                                default:
                                    break;
                            }
                            INTEXDBC.UpdateICC_ABAUFM(rx, 1);//这里是满足需求的关系，若是部分满足，则拆分数量

                            #endregion
                        }
                        else
                        {
                            #region====数量不足=====
                            rx["ABAAUFTYP"] = pSType;
                            rx["ABAAUFKRS"] = pSKRS;
                            rx["ABAAUFLFD"] = pSLFD;
                            rx["ABAAUFPOS"] = pSPOS;
                            rx["ABARESMG"] = pSQTY;
                            switch (pSType)
                            {
                                case "B":
                                    rx["ABAQTYALLOCATE"] = pSQTY;
                                    rx["ABAQTYRESERVE"] = 0;
                                    dwITXSTOCK["QTYFREE"] = 0;
                                    break;
                                case "P":
                                    rx["ABAQTYALLOCATE"] = 0;
                                    rx["ABAQTYRESERVE"] = pSQTY;
                                    dwITXEKPOS["EKPQTYFREE"] = 0;
                                    break;
                                default:
                                    break;
                            }
                            // ABAQTYALLOCATE,ABAQTYRESERVE,ABAQTYRECEIVED,
                            INTEXDBC.UpdateICC_ABAUFM(rx, 1);//这里是满足需求的关系，若是部分满足，则拆分数量                               
                            DataRow ry = SetData.ICC_ABAUFM.NewRow();
                            ry.ItemArray = rx.ItemArray;
                            if (pSType == "P")
                            {
                                ry["ABARESMG"] = rqty - pSQTY;
                            }
                            if (pSType == "B")
                            {
                                ry["ABARESMG"] = (rqty - pSQTY);
                            }
                            INTEXDBC.InsertICC_ABAUFM(rx, 9);//要考虑唯一性
                            pSQTY = 0;
                            #endregion
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        #endregion
    }
}